package com.ddzh.job;

import com.ddzh.service.OrderSettingService;
import com.xxl.job.core.biz.model.ReturnT;
import com.xxl.job.core.handler.IJobHandler;
import com.xxl.job.core.handler.annotation.JobHandler;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;

@JobHandler(value = "job.ClearOrderSettingByDate")
@Component
public class ClearOrderSettingByDateJob extends IJobHandler {
    @Resource
    private OrderSettingService orderSettingService;
    @Override
    public ReturnT<String> execute(String s) throws Exception {
        System.out.println("调用了.............");
        //获取半年前今天的日期
        Date date=new Date();//取时间
        Calendar calendar = new GregorianCalendar();
        calendar.setTime(date);
        calendar.add(calendar.DATE,-180);//180之前
        date=calendar.getTime(); //这个时间就是180天之前的日期
        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
       String dateString = formatter.format(date);
        orderSettingService.deleteOrderSettingByDate(dateString);
        return SUCCESS;
    }
}
